from django.db import models
from apps.users.models import User

class StudyRecord(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    start_time = models.DateTimeField(verbose_name='开始时间')
    duration = models.IntegerField(verbose_name='学习时长(秒)')
    category = models.CharField(max_length=50, verbose_name='学习类别')
    notes = models.TextField(null=True, blank=True, verbose_name='学习笔记')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    class Meta:
        db_table = 'study_record'
        verbose_name = '学习记录'
        verbose_name_plural = verbose_name
        ordering = ['-created_at']

    def __str__(self):
        return f"{self.user.username} - {self.start_time}"
